package minesweeper;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.ImageObserver;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

class ImageLabel extends JLabel {
           Image image;
           ImageObserver imageObserver; 

           // constructor with filename         
           ImageLabel(String filename) {
                  ImageIcon icon = new ImageIcon(filename);
                  image = icon.getImage();
                  imageObserver = icon.getImageObserver();
           }

           // constructor with icon
           ImageLabel(ImageIcon icon) {
                  image = icon.getImage();
                  imageObserver = icon.getImageObserver();
           }

           // overload setIcon method
           void setIcon(ImageIcon icon) {
                  image = icon.getImage();
                  imageObserver = icon.getImageObserver();
           }

           // overload paint()
           public void paint(Graphics g) {
                   super.paint( g );
                   g.drawImage(image,  0 , 0 , getWidth() , getHeight() , imageObserver);
           }
           
           public void changeImage(String filename){
                   ImageIcon icon = new ImageIcon(filename);
                          image = icon.getImage();
                          imageObserver = icon.getImageObserver();
                          repaint();
           }
}